#include <stdio.h>
#include <stdlib.h>

//格式化读取
int main()
{
    // int a = 0;
    // int b = 0;
    // int c = 0;
    char *p = (char *)malloc(sizeof(char) * 50);
    FILE *fp = fopen("G:/Desktop/b.txt", "r");
    //遇到一个空格字符（空格字符可以是空白、换行和制表符）。
    // fscanf(fp, "%d\n", &a);
    // printf("%d", a);
    // fscanf(fp, "%d %d %d\n", &a, &b, &c);
    // printf("a = %d, b = %d, c = %d\n", a, b, c);
    fscanf(fp, "%s", p);
    printf("%s", p);
    fscanf(fp, "%s", p);
    printf("%s", p);
    fscanf(fp, "%s", p);
    printf("%s", p);
    fclose(fp);
    free(p);
}

//格式化写入
int main1()
{
    // char ch[] = "hello world";
    // char a[] = "你是真皮";
    char a[] = "hello";
    char b[] = "";
    char c[] = "world";
    FILE *fp = fopen("G:/Desktop/b.txt", "w");
    fprintf(fp, "%s %s %s", a, b, c);
    fclose(fp);
}